package com.sdkx.app.datalayers;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;

import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;

import com.sdkx.app.R;
import com.sdkx.app.gps.GpsManager;
import cn.creable.gridgis.display.Display;
import cn.creable.gridgis.geometry.IGeometry;
import cn.creable.gridgis.geometry.Point;
import cn.creable.gridgis.util.Image;

public class HelicopterPanel extends MapDraw {
    Point mPoint;
    Paint paint;
    Image image;

    public HelicopterPanel(Context context) {
        super(context);
        mPoint = mDefaultPoint;////        //40.065789//116.156985
        paint = new Paint();
        paint.setTextSize(18);
        paint.setFlags(Paint.ANTI_ALIAS_FLAG);
        BitmapDrawable bmpDraw = (BitmapDrawable) appContext.getResources().getDrawable(R.drawable.airplane);
        image = new Image(bmpDraw.getBitmap());
        GpsManager.getInstance().addLocationListener(new LocationListener() {
            @Override
            public void onLocationChanged(Location location) {
                if(location != null){
                    image.setAngle(location.getBearing());
                    mapControl.refresh();
                }
            }

            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {

            }

            @Override
            public void onProviderEnabled(String provider) {

            }

            @Override
            public void onProviderDisabled(String provider) {

            }
        });
    }
    @Override
    public IGeometry getGeometry(int i) {
        return mPoint;
    }

    @Override
    public int getGeometryNum() {
        return 1;
    }

    @Override
    public void onGeometrySelected(int i, IGeometry iGeometry) {

    }

    @Override
    protected void draw2(Canvas canvas, Display display) {
        Display d = (Display)display;
        Canvas oldG = d.getCanvas();
        d.setCanvas(canvas);
        Location location = GpsManager.getInstance().getLocation();
        if (location != null) {
            mPoint = new Point(location.getLongitude(), location.getLatitude());
            image.setAngle(location.getBearing());
        }
        d.DrawImagePoint(mPoint, image);
        d.setCanvas(oldG);
    }
}
